package com.lx.oms.controller.controller;

import java.math.BigInteger;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.lx.oms.common.annotation.SysLog;
import com.lx.oms.common.controller.AbstractController;
import com.lx.oms.common.entity.Page;
import com.lx.oms.common.entity.R;
import com.lx.oms.controller.entity.WOrderCategoryEntity;
import com.lx.oms.controller.entity.WOrderEntity;
import com.lx.oms.controller.service.WOrderCategoryService;
import com.lx.oms.controller.service.WOrderService;

/**
 * 微信接单
 * @author houzhong
 * @date 2018年8月08日 上午10:44:54
 */
@RestController
@RequestMapping("/sys/wreceiptorder")
public class WReceiptOrderController extends AbstractController {
	
	@Autowired
	private WOrderService wOrderService;
	
	@Autowired
	private WOrderCategoryService wOrderCategoryService;
	
	/**
	 * 列表
	 * @param params
	 * @return
	 */
	@RequestMapping("/list")
	public Page<WOrderEntity> list(@RequestBody Map<String, Object> params) {
		Page<WOrderEntity> list = wOrderService.listWOrder(params);
		if (list.getRows().size()>0) {
			for (WOrderEntity orderEntity : list.getRows()) {
				orderEntity.setProvince(orderEntity.getProvince()+orderEntity.getCity()+orderEntity.getArea());
				WOrderCategoryEntity categoryEntity = new WOrderCategoryEntity();
				categoryEntity.setOrderNumber(orderEntity.getOrderNumber());
				List<WOrderCategoryEntity> categoryEntities = wOrderCategoryService.listWOrderCategory(categoryEntity);
				orderEntity.setSrderCategorys(categoryEntities);
			}
		}
		return list;
	}
		
	/**
	 * 新增
	 * @param wOrder
	 * @return
	 */
	@SysLog("新增微信下单")
	@RequestMapping("/save")
	public R save(@RequestBody WOrderEntity wOrder) {
		return wOrderService.saveWOrder(wOrder);
	}
	
	/**
	 * 根据id查询详情
	 * @param id
	 * @return
	 */
	@RequestMapping("/info")
	public R getById(@RequestBody String id) {
		BigInteger bId = new BigInteger(id);
		return wOrderService.getWOrderById(bId);
	}
	
	/**
	 * 修改
	 * @param wOrder
	 * @return
	 */
	@SysLog("修改微信下单")
	@RequestMapping("/update")
	public R update(@RequestBody WOrderEntity wOrder) {
		return wOrderService.updateWOrder(wOrder);
	}
	
	/**
	 * 删除
	 * @param id
	 * @return
	 */
	@SysLog("删除微信下单")
	@RequestMapping("/remove")
	public R batchRemove(@RequestBody String[] id) {
		return wOrderService.batchRemove(id);
	}
	
	
}
